package com.shengyin.ec.service.cluster;

import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import com.shengyin.ec.model.dao.cluster.ChainCompanyDao;
import com.shengyin.ec.model.dao.goods.GoodsDao;
import com.shengyin.ec.model.entity.ChainCompany;
import com.shengyin.ec.model.entity.Goods;

@Service("chainCompanyService")
public class ChainCompanyServiceImpl implements ChainCompanyService {
	
	@Autowired
	ChainCompanyDao chainCompanyDao;
	
	@Autowired
	GoodsDao goodsDao;

	@Override
	public List<ChainCompany> getChainCompanyList() {
		return chainCompanyDao.getChainCompanyList();
	}

	@Override
	public void createChainCompany(ChainCompany company) {
		chainCompanyDao.save(company);
	}

	@Override
	public void removeChainCompanyById(long id) {
		chainCompanyDao.deleteByKey(id);
	}

	@Override
	public void modifyChainCompany(ChainCompany company) {
	//	ChainCompany company1= chainCompanyDao.get(company.getId());
		//chainCompanyDao.update(company1);
	}


	@Override
	public ChainCompany getChainCompanyById(long id) {
		return chainCompanyDao.get(id);	
	}

	public boolean checkChainCompanyUser(String username, String pwd){
		return chainCompanyDao.checkChainCompanyUser(username, pwd);
	}

	

	//add by wql 2012-3-20
	@Override
	public List<ChainCompany> getChainCompanyList(int offset,int pagesize){
		return chainCompanyDao.getChainCompanyList(offset,pagesize);
	}
    
	@Override
	public List<ChainCompany> getChainCompany(int status,int offset,int pagesize){
		return chainCompanyDao.getChainCompany(status,offset,pagesize);
	}

	@Override
	public Long getTotal(){
		return chainCompanyDao.getTotal();
	}
	
	@Override
	public void deleteSelectedChainCompany(String[] ids) {
		if(ids!=null){
			Long[] idsl=new Long[ids.length];
			for(int i=0;i<ids.length;i++){
				if(ids[i]!=null||!ids[i].isEmpty()){
					idsl[i]=Long.valueOf(ids[i].trim());
				}
				
			}
			chainCompanyDao.deleteSelectedChainCompany(idsl);
			}
		
	}

	@Override
	public List<ChainCompany> getChainCompany(int status) {
		return null;
	}

	@Override
	public List<ChainCompany> getChainCompanyByName(String username) {
		
		return chainCompanyDao.getChainCompanyByName(username);
	}

	/*
	 * lining
	 * */
	@Override
	public List<Goods> getGoodsListByChainCompanyId(long id) {
		return goodsDao.getGoodsListByChainCompanyId(id);
	}

	@Override
	public List<ChainCompany> getChainChainCompanyListByChainCompanyId(long id) {
		return chainCompanyDao.getChainCompanyListByChainCompanyId(id);
	}

	@Override
	public void createChainChainCompany(ChainCompany chainChainCompany) {
		// TODO Auto-generated method stub
		
	}

	@Override
	public void deleteSelectedCluster(String[] ids) {
		// TODO Auto-generated method stub
		
	}
	
    public List<ChainCompany> getChainCompanyListByCluster(long clusterCompanyid,int offset,int pageSize){
    	
    	return chainCompanyDao.getChainCompanyListByCluster(clusterCompanyid,offset,pageSize);
    }
	
	public List<ChainCompany> getChainCompanyListByCluster(long clusterCompanyid){
		
		return chainCompanyDao.getChainCompanyListByCluster(clusterCompanyid);
	}
	
    public List<ChainCompany> searchChainByName(String[] paramValues ,int offset,int pageSize){
    	
    	return chainCompanyDao.searchChainByName(paramValues,offset,pageSize);
    }
	
	public List<ChainCompany> searchChainByName(String[] paramValues){
		
		return chainCompanyDao.searchChainByName(paramValues);
	}
}
